<!-- *Author: 黄旗, *Date: 2020-08-04 15:45:59 -->
<template>
    <Drawer title="日志信息" :width="65" :mask-closable="false" v-model="drawer">
        <JG-search :searchData="searchData" @on-change-change="askDatas"/>
        <JG-table
            :params="params"
            :data="data"
            :columns="columns"
            :loading="loading"
            :total="total"
            @askData="askData"></JG-table>
    </Drawer>
</template>

<script>
    import { copyindexcopylogs } from "@api/copytext"
    export default {
        name: '',
        components: {},
        
        data() {
            return {
                drawer: false,
                searchData: {
                    left: [
                        { id: 1, key: 'DatePicker', value: [new Date(), new Date()], type:'daterange', clearable: true, placeholder: '请选择时间', callback: 'change' },
                        { id: 2, key: 'RadioGroup', value: '', type: 'button', buttonStyle: 'solid', childList: [{ value: '', label: '全部' }, { value: '1', label: '成功' }, { value: '2', label: '失败' }], callback: 'change' },
                    ],
                },
                loading: false,
                total: 0,
                params: { start_time: '', end_time: '', state: '', page: 1, pageSize: 10 },
                columns: [
                    { title: '原网站URL', key: 'source_url', width: 180, ellipsis: true, tooltip: true },
                    { title: '原网站文章ID', key: 'article_id', width: 145 },
                    { title: '目标网站URL', key: 'target_url', width: 180, ellipsis: true, tooltip: true },
                    { title: '目标网站栏目ID', key: 'cid', width: 145 },
                    { title: '执行时间', key: 'dates', width: 170 },
                    { title: '执行状态', key: 'state', width: 100,
                        render: (h, params) => {
                            return h("div", {}, +params.row.state === 1?'成功':'失败');
                        }
                    },
                    { title: '操作人', key: 'operate_name', width: 90 },
                    { title: '操作', slot: 'copytextTitle',minWidth: 160 },
                ],
                data: []
            };
        },
        mounted() {
        },
        /* 函数方法集合 */
        methods: {
            /* @函数功能: 初始化 */
            initial() {
                this.drawer = true
                this.askData()
            },
            askDatas() {
                this.params.page = 1
                this.askData()
            },
            askData() {
                this.searchData.left.forEach((item) => {
                    if (item.id === 1) {
                        this.params.start_time = item.value[0]?this.$Date(item.value[0]).format("YYYY-MM-DD"):''
                        this.params.end_time = item.value[1]?this.$Date(item.value[1]).format("YYYY-MM-DD"):''
                    } else if (item.id === 2) {
                        this.params.state = item.value
                    }
                });
                this.loading = true
                copyindexcopylogs(this.params).then(res=>{
                    this.data = res.list
                    this.total = res.total
                    this.loading = false
                }).catch(() => {
                            this.loading = false;
                });
            },
        }
    }
</script>